package com.walker.controller.panorama;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.walker.service.panorama.AssetPanoramaService;

import net.sf.json.JSONObject;

/**
 *资产全景 
 */
@RestController
@RequestMapping("assetPanorama")
public class AssetPanoramaController {

	private static final Log log = LogFactory.getLog(AssetPanoramaController.class);
	
	@Resource
	private AssetPanoramaService service;

	@DeleteMapping(value = "/project/{deployName}")
	public String del(@PathVariable String deployName) {
		JSONObject json = new JSONObject();
		try {
			json.put("data",deployName);
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 业务板块视图
	 * @param request
	 * @param response
	 * @return
	 */
	@PostMapping("getBusinessPlateViewInfo")
	public String getBusinessPlateViewInfo(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			List<Map<String,Object>> list = service.getBusinessPlateViewInfo();
			json.put("data",list);
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 全景总览信息
	 * @param request
	 * @param response
	 * @return
	 */
	@PostMapping("getPanoramicOverviewInfo")
	public String getPanoramicOverviewInfo(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			Map<String,Object> datas = service.getPanoramicOverviewInfo();
			json.put("data",datas);
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 流动总表数
	 * @param request
	 * @param response
	 * @return
	 */
	@PostMapping("getFlowTablesNumber")
	public String getFlowTablesNumber(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			List<Map<String,Object>> list = service.getFlowTablesNumber();
			json.put("data",list);
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 数据接入top5
	 * @param request
	 * @param response
	 * @return
	 */
	@PostMapping("getDataAccessTop5")
	public String getDataAccessTop5(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			List<Map<String,Object>> list = service.getDataAccessTop5();
			json.put("data",list);
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 数据接入least5
	 * @param request
	 * @param response
	 * @return
	 */
	@PostMapping("getDataAccessLeast5")
	public String getDataAccessLeast5(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			List<Map<String,Object>> list = service.getDataAccessLeast5();
			json.put("data",list);
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 数据接入总进度
	 * @param request
	 * @param response
	 * @return
	 */
	@PostMapping("getDataAccess")
	public String getDataAccess(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			json.put("data",service.getDataAccess());
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			} 
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 资产-流动-应用服务
	 * @param request
	 * @param response
	 * @return
	 */ 
	@PostMapping("getAssetServiceInfo")
	public String getAssetServiceInfo(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			json.put("data",service.getAssetServiceInfo());
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	/**
	 * 资产-结构-业务板块信息
	 * @param request
	 * @param response
	 * @return
	 */ 
	@PostMapping("getBusinessList")
	public String getBusinessList(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			json.put("data",service.getBusinessList());
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
	
	/**
	 * 资产-结构-实体信息
	 * @param request
	 * @param response
	 * @return
	 */ 
	@PostMapping("getEntityList")
	public String getEntityList(HttpServletRequest request, HttpServletResponse response) {
		String busin_id = request.getParameter("busin_id");
		JSONObject json = new JSONObject();
		try {
			json.put("data",service.getEntityList(busin_id));
			json.put("flag", true);
		} catch (Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("flag", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
}